// house_pkg/pages/locate/index.ts
// 导入地图 SDK  的实例化 对象
import qqMap from '../../../utils/qqMap'


Page({
  goBuilding(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/building/index?point=' + ev.mark.point
    })
  },
  onLoad() {
    this.getLocation ()
  },

  // 获取用户地址经纬度
  async getLocation () {
    const { latitude, longitude} = await wx.getLocation()
    console.log(latitude,longitude);
    this.getPoint(latitude, longitude)
  },
  async chooseLocation() {
  const {latitude, longitude} = await wx.chooseLocation() 

    console.log(latitude, longitude);
    this.getPoint(latitude, longitude)
  },
  getPoint(latitude, longitude) {
    qqMap. reverseGeocoder({
      location:[latitude, longitude].join(','),
      success:(res) =>{
        console.log(res.result.address);
        this.setData({
          address:res.result.address
        })

        qqMap.search({
          keyword:'小区',
          location:[latitude, longitude].join(','),
          page_size:5,
          success:(res) => {
            console.log(res);
            this.setData({
              points:res.data
            })
          }

        })
      }
    })
  }
})